#ifndef __hw_timebase_10k_h
#define __hw_timebase_10k_h

#include "driverlib.h"
#include "device.h"
#include "board.h"
#include "user.h"

#define MAX_ST_NUM              8

typedef enum
{
    CYCLE_STOP=0,
    CYCLE_END,
    CYCLE_RUNNING,
    CYCLE_READY,
}CounterState_E;

typedef enum
{
    MODE_CYCLE=0,
    MODE_ONCE,
}CounterMode_E;

typedef struct
{
    uint8_t counterFlag;
    uint32_t countIndex;
    uint32_t startTime1;
    uint32_t startTime2;
    uint32_t stopTime1;
    uint32_t stopTime2;
    CounterState_E state;
}timeBaseCounter_T;

//typedef struct
//{
//    uint16_t RxTimeCount;
//    uint16_t TxTimeCount;
//    uint8_t RxTimeOut;
//    uint8_t TxTimeOut;
//}ModbusTimeOut_T;

typedef struct
{
    uint8_t ST_num;
    uint32_t timeOutSetVal;
    uint32_t Count;
    CounterState_E state;
    CounterMode_E mode;
    bool flag;

}SOFTTIME_LIST_T;

__interrupt void cpuTimer0ISR(void);
__interrupt void cpuTimer2ISR(void);

void ST_setTimerTimeOut(uint8_t ST_Num,uint32_t outTime);
bool ST_checkTimerFlag(uint8_t ST_Num);
void ST_reloadTimer(uint8_t ST_Num);
void ST_stopTimer(uint8_t ST_Num);
void ST_startTimer(uint8_t ST_Num);
void ST_startTimer_noReload(uint8_t ST_Num);
void ST_setTimerMode(uint8_t ST_Num,CounterMode_E mode);

//#if USE_MODBUS
//void USER_ModbusCBInit(void);
//uint8_t USER_checkModbusRxOut(void);
//uint8_t USER_checkModbusTxOut(void);
//void USER_clearModbusRxCount(void);
//void USER_clearModbusTxCount(void);
//void USER_clearModbusRxOut(void);
//void USER_clearModbusTxOut(void);
//#endif

void initCPUTimers(void);
void timebase_cupTim0Init(void);
void configCPUTimer(uint32_t cpuTimer, float freq, float period);

#endif // !__hw_timebase_10k_h
